import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HJ65 {
    public static void main(String[] args) {
        /**
         * 要求最长的公共子段
         * 从短一点的字符串开始入手，遍历每一个字符，如果相同则进行拼接，然后存入一个list集合中
         * 使用while循环加两个变量索引
         */
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        if(s1.length() <= s2.length()){
            System.out.println(fangfa(s1,s2));
        }else {
            System.out.println(fangfa(s2,s1));
        }
    }

    private static String fangfa(String s1,String s2){
        if(s2.contains(s1)){
            return s1;
        }

        int len = s1.length()-1;
        for (int i = 0; i < s1.length(); i++) {
            if(i+len<=s1.length()){
                String substring = s1.substring(i, i + len);
                if(s2.contains(substring)){
                    return substring;
                }
            }else {
                len--;
                i = -1;
            }
        }
        return null;
    }
}
